package org.dydl.common.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 中文姓名匹配
 * @author shichao
 *
 */
public class Validator {

	/**
	 * 中文姓名匹配。部分少数民族的姓名中包含字符'·'，其对应的Unicode编码为00B7
	 * @param name
	 * @return
	 */
	public static boolean isValidatedChineseName(String name) {
		name = new String(name.getBytes());// 用GBK编码
		String pattern = "^[\\u4e00-\\u9fa5]+[\\u00B7]?[\\u4e00-\\u9fa5]+$";
		Pattern p = Pattern.compile(pattern);
		Matcher result = p.matcher(name);
		return result.find();
	}
	
	 /**
     * 判断邮箱是否合法
     * @param email
     * @return
     */
    public static boolean isValidatedEmail(String email){  
        if (null==email || "".equals(email)) return false;    
        //Pattern p = Pattern.compile("\\w+@(\\w+.)+[a-z]{2,3}"); //简单匹配  
        Pattern p =  Pattern.compile("\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*");//复杂匹配  
        Matcher m = p.matcher(email);  
        return m.matches();  
    } 
    /**
     * 判断手机号是否合法
     * @param phone
     * @return 
     */
	public static boolean isValidatedMobilePhoneNumber(String phone){  
		Pattern p = Pattern.compile("^((13[0-9])|(14[579])|(15[^4,\\D])|(17[0,5-8])|(18[0-9]))\\d{8}$");  
		Matcher m = p.matcher(phone);  
		return m.matches();
		} 

}
